import BiaofunRegionTwoLevel from "@/components/biaofun-region/biaofun-region-two-level.vue"; //组件
import lawTopBar from "@/components/lawTopBar/index.vue"; //组件
import { getTaxList, getCateList } from "@/static/js/law.js"; //js
export default {
  components: {
    lawTopBar,
    BiaofunRegionTwoLevel,
  },
  data() {
    return {
      title: "优惠政策",
      backgroundUrl: require("@/static/img/law/topBar_bg_01.png"),
      scrollTop: 0,
      chooseTabId: 1, //分类选中下标
      tabsList: [
        {
          id: 1,
          nid: 1,
          name: "税收优惠政策",
        },
        {
          id: 2,
          nid: 2,
          name: "政府补助",
        },
      ],

      potencyList: [
        {
          id: "现行有效",
        },
        {
          id: "部分失效/废止",
        },
        {
          id: "全文失效/废止",
        },
        {
          id: "已修订",
        },
      ], //效力
      potencyIndex: -1, //效力选中下标
      indexType: -1, //税种选中下标
      taxTypeList: [], //税种类目
      form: {
        city_code: "", //	否	string	城市编码
        policy_cate_id: "",
        xiaoli_id: "",
        status: "", //政府补助 2
				type: 1, //	是	string	类型:1=优惠政策,2=财税法规
      },
      query: {
        page: 1,
        limit: 10,
      },
      isLoading: false,
      loadMoreStatue: "more",
      lawList: [],
      isRefreshing: false,
      loadMoreStatus: "more",
      regionName: [], //省市区名
      isShowImg: true,
    };
  },
  methods: {
    //去搜索页面
    goSearch() {
      uni.navigateTo({
        url: "/law/dis/search/index",
      });
    },

    //选择分类,重置部分参数
    chooseTab(item, index) {
      this.chooseTabId = item.id; //分类选中下标
      if (index == 0) {
        this.form.status = "";
        this.form.type = 1;
      } else {
        this.form.status = 2;
        this.form.type = "";
      }
      this.query.page = 1; //重置页码
      this.form.city_code = ""; //重置城市code码
      this.regionName = ""; //重置城市名
      this.form.policy_cate_id = ""; //重置税种id
      this.form.xiaoli_id = ""; //重置效力id
      this.lawList = []; //重置列表
      this.indexType = -1; //重置税种下标
      this.potencyIndex = -1; //重置效力下标
      this.keyword = ""; //重置关键字
      this.form.keyword = ""; //重置关键字
      this.getList();
    },

    //选择省市
    changeRegion(res) {
      this.regionName = res;
      this.form.city_code = res[1].id;
      this.query.page = 1;
      this.getList();
    },
    //取消省市区选择
    changeRegions1() {
      this.regionName = "";
      this.form.city_code = "";
      this.query.page = 1;
      this.getList();
    },
    //税种选择
    taxTypeChange(res) {
      let index = res.detail.value;
      this.indexType = index;
      this.form.policy_cate_id = this.taxTypeList[index].id;
      this.query.page = 1;
      this.getList();
    },
    //税种取消选择
    taxTypeCancel() {
      this.indexType = -1;
      this.form.policy_cate_id = "";
      this.query.page = 1;
      this.getList();
    },
    //效力选择
    potencyChange(res) {
      this.potencyIndex = res.detail.value;
      this.form.xiaoli_id = this.potencyList[this.potencyIndex].id;
      this.query.page = 1;
      this.getList();
    },
    //效力取消选择
    potencyCancel() {
      this.potencyIndex = -1;
      this.form.xiaoli_id = "";
      this.query.page = 1;
      this.getList();
    },

    //请求列表数据
    getList() {
      if (this.query.page == 1) {
        this.dataList = [];
        this.isLoading = true;
      } else {
        this.loadMoreStatue = "loading";
      }
      let queryData = {
        ...this.form,
        ...this.query,
      };
      getTaxList(queryData).then((res) => {
        if (res.code == 1) {
          if (this.query.page == 1) {
            this.lawList = [];
          }
          var newList = res.data;
          if (newList.length >= this.query.limit) {
            this.loadMoreStatus = "more";
          } else {
            this.loadMoreStatus = "noMore";
          }
          this.lawList = [...this.lawList, ...newList];
          this.isRefreshing = false;
        } else {
          this.$tools.showToast(res.msg);
          this.loadMoreStatus = "noMore";
        }
      });
    },

    //下拉刷新
    reload() {
      this.query.page = 1;
      this.lawList = [];
      this.isRefreshing = true;
      this.getList();
    },

    //加载更多
    loadMore() {
      if (this.loadMoreStatus == "more") {
        this.query.page++;
        this.getList();
      } else {
        this.$tools.msg("没有更多了");
      }
    },

    //去詳情
    toInfo(id) {
      uni.navigateTo({
        url: `../../tax/det/index?id=${id}&type=1`,
      });
    },

    //获取税种
    getTaxType() {
      getCateList({})
        .then((res) => {
          if (res.code == 1) {
            this.taxTypeList = res.data;
          } else {
            this.$tools.showToast(res.msg);
          }
        })
        .catch((err) => {
          console.log("错误回调", err);
        });
    },
  },
  onReady() {},
  onLoad(e) {
    this.getList();
    this.getTaxType();
  },
  onShow() {},
};